package com.coders.android.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.coders.android.hibernate.dto.Usuario;
import com.coders.android.spring.service.UsuarioService;

@Path("android/usuario")
@Component
public class UsuarioServiceREST {

	@Autowired
	UsuarioService usuarioService;	
		
	@Produces(MediaType.APPLICATION_JSON)
	@Path("registrar/{imei}/{latitud}/{longitud}")
	@GET
	public String insertar(
			@PathParam( "imei" ) String imei,
			@PathParam( "latitud" ) double latitud,
			@PathParam( "longitud" ) double longitud ) {
		
		try {
			usuarioService.insertar( new Usuario(imei, latitud, longitud) );
			return "OK";
			
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}
	
	@Produces(MediaType.APPLICATION_JSON)
	@Path("eliminar/{imei}")
	@GET
	public String eliminar( @PathParam( "imei" ) String imei ) {
	
		try {
			usuarioService.eliminar( imei );
			return "OK";
			
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}	
}
